package com.wtgroup.demo.foo;


import lombok.SneakyThrows;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author dafei
 * @version 0.1
 * @date 2021/3/9 16:06
 */
public class Foo {

    @SneakyThrows
    public static void main(String[] args) {
        ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<>(10);

        new Thread(() -> {
            int i = 0;
            while (true) {
                try {
                    Thread.sleep(1000);
                    queue.put(++i);
                    System.out.println("生产数据: " + i);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }).start();

        new Thread(() -> {
            while (true) {
                Integer poll = null;
                try {
                    poll = queue.take();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("消费数据: " + poll);
            }
        }).start();

        Thread.currentThread().join();
    }

    void func() {
        func0(); // 可能需要改成包在循环里
    }

    void func0() {
        // func0(); -- dp表里取值
        // return xx; -- 填入dp表
    }

}


